1585B - Array Eversion - CodeForces Solution


greedy *900

Please click on ads to support us..

Python Code:

t = int(input())
while t:
    n = int(input())
    arr = list(map(int,input().split()))
    max = 0
    count = 0
    for i in arr[::-1]:
        if i > max:
            max = i
            count += 1
    print(count-1)
    t -= 1

C++ Code:

#include<cstdio>
int s,_,n,ans,a[200001],i;
int main(){
	scanf("%d",&_);
	while(_--){
		scanf("%d",&n);s=ans=-1;
		for(i=1;i<=n;i++)scanf("%d",&a[i]);
		for(i=n;i>=1;i--)if(a[i]>s)s=a[i],ans++;
		printf("%d\n",ans);
	}
}


Comments

Submit
0 Comments
More Questions

429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good
1C - Ancient Berland Circus
721A - One-dimensional Japanese Crossword
1715B - Beautiful Array
60B - Serial Time
453A - Little Pony and Expected Maximum
1715A - Crossmarket
1715C - Monoblock
1512C - A-B Palindrome
1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions
1582A - Luntik and Concerts
560A - Currency System in Geraldion
946A - Partition
1068B - LCM
1692E - Binary Deque
679A - Bear and Prime 100